package com.ruoyi.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysOption;
import com.ruoyi.project.system.service.ISysOptionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 单字段Controller
 *
 * @author theme
 * @date 2020-05-27
 */
@Api(description = "表单字段维护" )
@RestController
@RequestMapping("/system/option" )
public class SysOptionController extends BaseController {
    @Autowired
    private ISysOptionService sysOptionService;

/**
 * 查询单字段列表
 */
@ApiOperation("查询单字段列表" )
@PreAuthorize("@ss.hasPermi('system:option:list')" )
@GetMapping("/list" )
        public TableDataInfo list(SysOption sysOption) {
        startPage();
        List<SysOption> list = sysOptionService.selectSysOptionList(sysOption);
        return getDataTable(list);
    }
    
    /**
     * 获取单字段详细信息
     */
    @ApiOperation("获取单字段详细信息" )
    @PreAuthorize("@ss.hasPermi('system:option:query')" )
    @GetMapping(value = "/{optionId}" )
    public AjaxResult getInfo(@PathVariable("optionId" ) Long optionId) {
        return AjaxResult.success(sysOptionService.selectSysOptionById(optionId));
    }

    /**
     * 新增单字段
     */
    @ApiOperation("新增单字段" )
    @PreAuthorize("@ss.hasPermi('system:option:add')" )
    @Log(title = "单字段" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOption sysOption) {
        return toAjax(sysOptionService.insertSysOption(sysOption));
    }

    /**
     * 修改单字段
     */
    @ApiOperation("修改单字段" )
    @PreAuthorize("@ss.hasPermi('system:option:edit')" )
    @Log(title = "单字段" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOption sysOption) {
        return toAjax(sysOptionService.updateSysOption(sysOption));
    }

    /**
     * 删除单字段
     */
    @ApiOperation("删除单字段" )
    @PreAuthorize("@ss.hasPermi('system:option:remove')" )
    @Log(title = "单字段" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{optionIds}" )
    public AjaxResult remove(@PathVariable Long[] optionIds) {
        return toAjax(sysOptionService.deleteSysOptionByIds(optionIds));
    }
}
